<template>
  <div>
    <p-form :form="form">
      <p-row>

        <p-col :span="12">
          <p-form-item label="主键" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'id', validatorRules.id]" placeholder="请输入主键"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'code', validatorRules.code]" placeholder="请输入供应商编码"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'name', validatorRules.name]" placeholder="请输入供应商名称"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="默认交易币别" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'defaultCurrency', validatorRules.defaultCurrency]" placeholder="请输入默认交易币别"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="默认语言" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'defaultLanguage', validatorRules.defaultLanguage]" placeholder="请输入默认语言"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="供应商组" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'supplierGroup', validatorRules.supplierGroup]" placeholder="请输入供应商组"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="采购组" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'procurementGroup', validatorRules.procurementGroup]" placeholder="请输入采购组"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="外部系统编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'externalCode', validatorRules.externalCode]" placeholder="请输入外部系统编码"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="年销售额" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input-number v-decorator="[ 'annualSales', validatorRules.annualSales]" placeholder="请输入年销售额" style="width: 100%"/>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="付款条件" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'paymentClause', validatorRules.paymentClause]" placeholder="请输入付款条件"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="合作年限" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'cooperativeLength', validatorRules.cooperativeLength]" placeholder="请输入合作年限"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="绩效评级" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'performanceRating', validatorRules.performanceRating]" placeholder="请输入绩效评级"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="企业性质" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'enterpriseProperty', validatorRules.enterpriseProperty]" placeholder="请输入企业性质"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="企业税务信用等级" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'taxClass', validatorRules.taxClass]" placeholder="请输入企业税务信用等级"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="能力分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'abilityType', validatorRules.abilityType]" placeholder="请输入能力分类"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="企业类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'companyCategory', validatorRules.companyCategory]" placeholder="请输入企业类别"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="增值税率" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'taxRate', validatorRules.taxRate]" placeholder="请输入增值税率"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="采购员" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'buyer', validatorRules.buyer]" placeholder="请输入采购员"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="行业" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'industryClass', validatorRules.industryClass]" placeholder="请输入行业"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="能力分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'abilityGroup', validatorRules.abilityGroup]" placeholder="请输入能力分类"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="更新人标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'updatetimeBy', validatorRules.updatetimeBy]" placeholder="请输入更新人标识"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'updatetimeTime', validatorRules.updatetimeTime]" placeholder="请输入更新时间"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="时间标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'timestamp', validatorRules.timestamp]" placeholder="请输入时间标识"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="公司标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'companyId', validatorRules.companyId]" placeholder="请输入公司标识"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="工厂标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'factoryId', validatorRules.factoryId]" placeholder="请输入工厂标识"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="租户标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'clientId', validatorRules.clientId]" placeholder="请输入租户标识"></p-input>
          </p-form-item>
        </p-col>
        <p-col :span="12">
          <p-form-item label="替换人员标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <p-input v-decorator="[ 'substituteId', validatorRules.substituteId]" placeholder="请输入替换人员标识"></p-input>
          </p-form-item>
        </p-col>
      </p-row>
    </p-form>
  </div>
</template>
<script>
  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'

  export default {
    name: 'SupplierDetailForm',
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelCol2: {
          span: 3
        },
        wrapperCol2: {
          span: 20
        },
        confirmLoading: false,
        validatorRules:{
          code:{},
          name:{rules: [{ required: true, message: '请输入供应商名称!' }]},
          defaultCurrency:{},
          defaultLanguage:{},
          supplierGroup:{},
          procurementGroup:{},
          externalCode:{},
          annualSales:{},
          paymentClause:{},
          cooperativeLength:{},
          performanceRating:{},
          enterpriseProperty:{},
          taxClass:{},
          abilityType:{},
          companyCategory:{},
          taxRate:{},
          buyer:{},
          industryClass:{},
          abilityGroup:{},
          updatetimeBy:{},
          remark:{},
          updatetimeTime:{},
          timestamp:{},
          companyId:{},
          factoryId:{},
          clientId:{},
          substituteId:{},
        },
        
      }
    },
    methods:{
      initFormData(url,id){
        this.clearFormData()
        if(!id){
          this.edit({})
        }else{
          getAction(url,{id:id}).then(res=>{
            if(res.success){
              let records = res.data
              if(records && records.length>0){
                this.edit(records[0])
              }
            }
          })
        }
      },
      edit(record){
        this.model = Object.assign({}, record)
        console.log("SupplierDetailForm-edit",this.model);
        let fieldval = pick(this.model,'code','name','defaultCurrency','defaultLanguage','supplierGroup','procurementGroup','externalCode','annualSales','paymentClause','cooperativeLength','performanceRating','enterpriseProperty','taxClass','abilityType','companyCategory','taxRate','buyer','industryClass','abilityGroup','updatetimeBy','remark','updatetimeTime','timestamp','companyId','factoryId','clientId','substituteId')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
      },
      getFormData(){
        let formdata_arr = []
        this.form.validateFields((err, values) => {
          if (!err) {
            let formdata = Object.assign(this.model, values)
            let isNullObj = true
            Object.keys(formdata).forEach(key=>{
              if(formdata[key]){
                isNullObj = false
              }
            })
            if(!isNullObj){
              formdata_arr.push(formdata)
            }
          }else{
            this.$emit("validateError","供应商档案明细表表单校验未通过");
          }
        })
        console.log("供应商档案明细表表单数据集",formdata_arr);
        return formdata_arr;
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'code','name','defaultCurrency','defaultLanguage','supplierGroup','procurementGroup','externalCode','annualSales','paymentClause','cooperativeLength','performanceRating','enterpriseProperty','taxClass','abilityType','companyCategory','taxRate','buyer','industryClass','abilityGroup','updatetimeBy','remark','updatetimeTime','timestamp','companyId','factoryId','clientId','substituteId'))
      },
      clearFormData(){
        this.form.resetFields()
        this.model={}
      }
    
    }
  }
</script>
